<?php

namespace App\Http\Resources;

use App\Goods;
use Illuminate\Http\Resources\Json\Resource;

class DealersResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $goods = $GLOBALS['goods'];
        return [
            'userNum' => $this->username,
            'password' => $this->password,
            'userName' => $this->market_level,
            'company' => $this->company,
            'market' => $this->market,
            'area' => $this->region,
            'goodsCnt' => $this->getAllGoodsCount(),
            'goodsOrder' => [
                [
                    'productId' => 1,
                    'imageUrl' => $goods[0]->avatar,
                    'price' => $goods[0]->price,
                    'productSum' => $this->goods_1,
                    'min' => get_min_from_market_level($this->market_level, 1),
                ],
                [
                    'productId' => 2,
                    'imageUrl' => $goods[1]->avatar,
                    'price' => $goods[1]->price,
                    'productSum' => $this->goods_2,
                    'min' => get_min_from_market_level($this->market_level, 2),
                ],
                [
                    'productId' => 3,
                    'imageUrl' => $goods[2]->avatar,
                    'price' => $goods[2]->price,
                    'productSum' => $this->goods_3,
                    'min' => get_min_from_market_level($this->market_level, 3),
                ],
                [
                    'productId' => 4,
                    'imageUrl' => $goods[3]->avatar,
                    'price' => $goods[3]->price,
                    'productSum' => $this->goods_4,
                    'min' => get_min_from_market_level($this->market_level, 4),
                ],
                [
                    'productId' => 5,
                    'imageUrl' => $goods[4]->avatar,
                    'price' => $goods[4]->price,
                    'productSum' => $this->goods_5,
                    'min' => get_min_from_market_level($this->market_level, 5),
                ],
                [
                    'productId' => 6,
                    'imageUrl' => $goods[5]->avatar,
                    'price' => $goods[5]->price,
                    'productSum' => $this->goods_6,
                    'min' => get_min_from_market_level($this->market_level, 6),
                ],
            ],
            "moneySum" => set_decimal($this->getAllMoneyCount()),
        ];
    }
}
